import java.io.PrintWriter;
import java.util.HashMap;

class Block extends Node {

	private Node statementSequence = null;

	public Block(Node s) {
		statementSequence = s;
	}

	@Override
	public void print(PrintWriter pw) {

		pw.println("Node name : Begin");
		// assert(stat_seq_);
		if (statementSequence != null)
			statementSequence.print(pw);
		pw.println("Node name : End");
	}

	public String translate(HashMap<String, PrintWriter> pws, String condition,
			SymbolTable st, String parent) {
		if (condition != null && condition.equals("button")) {
			if(st.getStack().size() > 1) {
				System.out.println("popped: " + st.getStack().pop());
				return null;
			} else {
				System.out.println("popped: " + st.getStack().pop());
				return null;
			}
		} else {
			if (st.getStack().size() > 1) {
				String key = st.getStack().get(1);
				PrintWriter pw = pws.get(key);
				pw.println(" {");
				st.addLevel();
				// to be removed.
				if (statementSequence != null)
					// statementSequence.print(pw);
					statementSequence.translate(pws, null, st, parent);

				st.getStack().pop();
				st.minusLevel();
				for (int i = 0; i < st.getLevel() * 4; i++) {
					pw.print(" ");
				}
				pw.println("}");
				return null;
			} else {
				if (statementSequence != null)
					// statementSequence.print(pw);
					statementSequence.translate(pws, null, st, parent);
				return null;
			}
		}
	}
}
